//
//  HomeViewController.swift
//  WeiBOzhu
//
//  Created by STW-02 on 18/10/30.
//  Copyright © 2018年 STW-02. All rights reserved.
//

import UIKit

class HomeViewController : BaseViewController {
   
    lazy var titleBtn : TitleButton = TitleButton()
    lazy var popoverAnimation : PopoverAnimator = PopoverAnimator {[weak self] (presented) -> () in
        self?.titleBtn.isSelected = presented
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
          // 对象方法 而不是类方法
           visitorView.addRotationAnim ()
            // 判断用户是否已经登录 
        if !isLogin {
              return
        }
        
         // 设置 导航栏的内容
         setupNavigationBar()
            
           }

 
}
//named: "navigationbar_pop" named: "navigationbar_friendattention"
extension HomeViewController{
    
     func  setupNavigationBar () {
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName:"navigationbar_friendattention")
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName:"navigationbar_pop")
    
        // 3.设置titleView
        titleBtn.setTitle("coderwhy", for: UIControlState())
        titleBtn.addTarget(self, action: #selector(HomeViewController.titleBtnClick(_:)), for: .touchUpInside)
        navigationItem.titleView = titleBtn
    }
}


// MARK:- 事件监听的函数
extension HomeViewController {
    @objc fileprivate func titleBtnClick(_ titleBtn : TitleButton) {
        // 1.改变按钮的状态
        titleBtn.isSelected = !titleBtn.isSelected
        
        // 2.创建弹出的控制器
        let popoverVc = PopoverViewController()
        
        // 3.设置控制器的modal样式
        popoverVc.modalPresentationStyle = .custom
        // 设置转场动画的代理 
         popoverVc.transitioningDelegate = popoverAnimation
        popoverAnimation.presentedFrame =  CGRect(x: 100, y: 55, width: 200, height: 255)
        // 4.弹出控制器
        present(popoverVc, animated: true, completion: nil)
    }
}

